import { Component, OnInit, Inject  } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { UtilityService} from '../../../../../../service/utils.service';
import {appConfig} from '../../../../../../service/common';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {Router} from '@angular/router';
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
import { ActivatedRoute} from '@angular/router';
import { WorkitemModule } from '../../../../../../service/delivent/workItemModule';
import { BranchModule} from '../../../../../../service/delivent/brachModule';
import * as _ from 'lodash';
import * as moment from 'moment';


@Component({
  selector: 'app-stashlist',
  templateUrl: './stashlist.component.html',
  styleUrls: ['./stashlist.component.less']
})
export class StashlistComponent implements OnInit {

    constructor(
        private http: _HttpClient,
        private router: Router,
        private utilityService: UtilityService,
        public activatedRoute: ActivatedRoute,
        private modal: NzModalService,
        private nznot: NzNotificationService,
        @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
   
    ) { }

    workGuid: string; // 工作项guid
    data: any; // 数据
    isPagination = true; // 是否有分页
    pageIndex: number; // 当前页数
    total: number;
    pageTotal: number;
    isShowTotal: boolean;  // 是否显示总数
    showAdd: boolean;  // 是否显示按钮和新增
    page: any; // 翻页
    token:any;
 
    // 工作项guid
    headerDate = [  // 配置表头内容
        { label: '程序名称', value: 'fullName', isclick: true},
        { label: '变动类型', value: 'commitType', isclick: false },
        { label: '导出为', value: 'patchType', isclick: false},
        { label: '部署为', value: 'deployWhere', isclick: false},
    ];
    isData:boolean;
  
    isSpinning = true;
    isExport = true;
    ngOnInit() {
       this.token  = this.tokenService.get().token; // 绑定token
        this.workGuid = this.activatedRoute.snapshot.params.id; // 拿到父组件传过来的操作员的guid来进行操作
        this.isShowTotal = true;
        this.showAdd = true;
         if(this.tokenService.get().role === '开发组') {
             this.isExport = false;
         }
        this.getData();
    }

checkModalData = [];
    getData() {
      
         let index = '';
         let star = '';
         let end = '';
            let url='/sWorkitem/'+this.workGuid+'/stashListDetail'
            this.isSpinning = true;
        this.utilityService.getData(appConfig.testUrl  + url )
            .subscribe(
                (val) => {
             this.isSpinning = false;
              if(val.result.length !== 0){
                   this.isData = true
              }else{
                    this.isData = false
              }
               this.checkModalData = val.result;
             
              
               for  (let i = 0; i < this.checkModalData.length; i ++) {                         
                                for (let x = 0; x < this.checkModalData[i].deliveryPatchDetails.length; x ++) {

                                    for (let  y = 0; y < this.checkModalData[i].deliveryPatchDetails[x].fileList.length; y ++) {
                                           this.checkModalData[i].deliveryPatchDetails[x].fileList[y]['buttons'] = null
                                        if (this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPath) {
                                            index = this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPath.indexOf(this.checkModalData[i].projectName);
                                            this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPath = this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPath.substring(index, this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPath.length);
                                              if(this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPath.length > 60) {
                                                        star = this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPath.substr(0, 30)
                                                        end = this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPath.substr(this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPath.length - 30)
                                                            this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPathstr = star + '...' + end;
                                                        }else{
                                                           this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPathstr = this.checkModalData[i].deliveryPatchDetails[x].fileList[y].fullPath;
                                                     }

                              }
                                    }
                                }
                            }
            console.log(this.checkModalData)
                
        },   (error) => {
                   
                    this.nznot.create('error', error.code , error.msg);
                })
   
    }


getRouter(it){
      this.router.navigate([it,this.workGuid]);
}

}
